package com.mengniu.commerce.sync.api.factory;


import com.mengniu.commerce.sync.api.RemoteOrderService;
import com.mengniu.commerce.sync.api.base.MnResult;
import com.mengniu.commerce.sync.api.domain.CreateOrderModel;
import com.mengniu.commerce.sync.api.domain.ModifyOrderModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 新增订单降级处理
 *
 * @author yz_sm
 */
@Component
public class RemoteOrderFallbackFactory implements FallbackFactory<RemoteOrderService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteOrderFallbackFactory.class);

    @Override
    public RemoteOrderService create(Throwable throwable)
    {
        log.error("数据同步服务调用失败:{}", throwable.getMessage());
        return new RemoteOrderService()
        {
            @Override
            public MnResult createOrder(List<CreateOrderModel> list, String source)
            {
                return new MnResult("","新增订单失败:" + throwable.getMessage(),false);
            }

            @Override
            public MnResult modify(ModifyOrderModel modifyOrderModel, String source) {
                return new MnResult("","修改订单失败:" + throwable.getMessage(),false);
            }


        };
    }
}
